package org.onion.pattern.event.springboot.rocketmq.config;


import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.HashMap;
import java.util.Map;

@SuppressWarnings("WeakerAccess")
@Data
public class RocketMQEventProperties {

    private String accessKey;
    private String secretKey;

    /**
     * 消息队列服务器地址, 格式为: `host:port;host:port`
     */
    private String defaultNameServer;

    private String publishableNotifierTopic;

    private String defaultNamespace = "LOCAL";

    private ProducerProperties producer = new ProducerProperties();

    private CommonConsumerProperties consumer = new CommonConsumerProperties();

    private DynamicProperties dynamic = new DynamicProperties();


    @Data
    public static class ProducerProperties {
        //todo
        /**
         * 生产者组
         */
        private String group;

//        private String nameServer;

//        private String namespace = "LOCAL";

        /**
         * 发送消息的超时时间，单位：毫秒
         */
        private int sendMessageTimeout = 3000;

        /**
         * 消息压缩的阈值，默认4K
         */
        private int compressMessageBodyThreshold = 1024 * 4;

        /**
         * 同步消息发送失败后的最大重试次数，有可能导致发送重复消息
         */
        private int retryTimesWhenSendFailed = 2;

        /**
         * 异步消息发送失败后的最大重试次数，有可能导致发送重复消息
         */
        private int retryTimesWhenSendAsyncFailed = 2;

        /**
         * 发生失败时，是否尝试使用下一个BROKER进行发送
         */
        private boolean retryNextServer = false;

        /**
         * 最大能够允许的消息大小,默认64k
         */
        private int maxMessageSize = 1024 * 1024 * 4;

        private boolean enabledAutoCreateTopic = false;


        private int defaultTopicQueueNums = 16;

    }

    @Data
    public static final class DynamicProperties {
        private Map<String, ConsumerProperties> dynamicConsumer = new HashMap<>();

    }

    @EqualsAndHashCode(callSuper = true)
    @Data
    public static final class ConsumerProperties extends CommonConsumerProperties {

        private String group;
    }

    @Data
    public static class CommonConsumerProperties {
        //todo
        private Integer consumeThreadMax;

//        private String nameServer;

//        private String namespace;

        private boolean enabled = true;

        private boolean enabledAutoCreateTopic = true;

        private int topicQueueNums = 16;

    }

}
